/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.view;

import com.model.Member;
import com.model.Paket;
import com.tools.koneksi;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Satellite
 */
public class TableKontrol {

    private Connection conn;

    public TableKontrol(Connection koneksi) {
        this.conn = koneksi;
    }

    public static TableKontrol getKoneksiKategori() throws SQLException {
        koneksi k = new koneksi();
        TableKontrol kon = new TableKontrol(k.getDBConnection());
        return kon;
    }

    public List<Member> lihatSeluruhKategori() throws SQLException {
        PreparedStatement statement = null;
        ResultSet result = null;

        conn.setAutoCommit(false);

        statement = conn.prepareStatement("select * from member");

        result = statement.executeQuery();
        List<Member> kategoris = new ArrayList<Member>();
        while (result.next()) {
            Member kategori = new Member();
            kategori.setId(result.getString("id"));
            kategori.setNama(result.getString("nama"));
            kategori.setAlamat(result.getString("alamat"));
            kategori.setNo_telp(result.getString("notelp"));
            kategoris.add(kategori);

        }
        
        conn.commit();
        return kategoris;
    }
        public List<Paket> menu() throws SQLException {
        PreparedStatement statement = null;
        ResultSet result = null;

        conn.setAutoCommit(false);

        statement = conn.prepareStatement("select * from paket");

        result = statement.executeQuery();
        List<Paket> kategoris = new ArrayList<Paket>();
        while (result.next()) {
            Paket baru = new Paket();
            baru.setNamaPaket(result.getString("nama_paket"));
            baru.setHargaPaket(result.getInt("harga_paket"));
            baru.setNasi(result.getString("nasi"));
            baru.setLauk(result.getString("lauk"));
            baru.setSayur(result.getString("sayur"));
            baru.setKrupuk(result.getString("kerupuk"));
            baru.setMinum(result.getString("minum"));
            kategoris.add(baru);

        }
        
        conn.commit();
        return kategoris;
    }
}
